<?php
class ArticleController extends My_Controllers {
	public function indexAction() {
		$id = $this->_getParam ( 'id' );
		$news = $this->news->find ( $id );
		$news->current ()->news_view ++;
		$news->current ()->save ();
		
		$this->view->news = $news->current ();
		$this->view->doctor_arr = $this->user->find ( $news->current ()->news_uid )->toArray ();
		
		$this->view->lanmu_arr = $this->news->fetchAll ( array ('column_id = ?' => $news->current ()->column_id ), NULL, 10, 0 )->toArray ();
		$this->view->keshi_arr = $this->news->fetchAll ( array ('section_id = ?' => $news->current ()->section_id ), NULL, 10, 0 )->toArray ();
		
		$this->view->keshi = $this->keshi->find ( $news->current ()->section_id )->current ();
		$this->view->lanmu = $this->lanmu->find ( $news->current ()->column_id )->current ();
	}
	public function mainAction() {
		$id = $this->_getParam ( 'id' );
		$news = $this->news->find ( $id );
		$news->current ()->news_view ++;
		$news->current ()->save ();
		
		$this->view->news = $news->current ();
		$this->view->doctor_arr = $this->user->find ( $news->current ()->news_uid )->toArray ();
		
		$this->view->lanmu_arr = $this->news->fetchAll ( array ('column_id = ?' => $news->current ()->column_id ), NULL, 10, 0 )->toArray ();
		$this->view->keshi_arr = $this->news->fetchAll ( array ('section_id = ?' => $news->current ()->section_id ), NULL, 10, 0 )->toArray ();
		
		$this->view->keshi = $this->keshi->find ( $news->current ()->section_id )->current ();
		$this->view->lanmu = $this->lanmu->find ( $news->current ()->column_id )->current ();
	}
	public function listAction() {
		$select = new Zend_Db_Select ( $this->db );
		$select->from ( array ('n' => 'bc_news' ), array ('id', 'news_title', 'time', 'news_view', 'column_id', 'section_id' ) );
		$select->joinLeft ( array ('l' => 'bc_lanmu' ), 'n.column_id = l.id', array ('lname' => 'name' ) );
		$select->joinLeft ( array ('k' => 'bc_keshi' ), 'l.kid = k.id', array ('kename' ) );
		$select->where ( 'mode = ?', '1' );
		$select->where ( 'l.name != ?', '' );
		$select->where ( 'news_type = ?', 'article' );
		$select->limitPage ( 0, 32 );
		$select->order ( "news_view" )->order ( "id desc" );
		$select->order ( "time" );
		$sql = $select->__toString ();
		//		Zend_Debug::dump ( $sql );
		$this->view->news = $this->db->fetchAll ( $sql );
		//		Zend_Debug::dump ( $news_hot_arr );
	}
}
		
